<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<link rel="stylesheet" type="text/css" href="github2-rightpart.css" media="all">
<link rel="stylesheet" type="text/css" href="github1-contents.css">
<link rel="stylesheet" type="text/css" href="zTreeStyle.css" >
<link rel="stylesheet" type="text/css" href="common.css" >
</head>
<body>

<!-- html -->
<div class="markdown-body" style="margin: 20px;">
    <h1>配置项</h1>
    <table class="api-config">
        <tr>
            <th>HTTP请求地址</th><td> <input id="url" type="text" value="" /> </td>
        </tr>
        <tr>
            <th>app_key</th><td> <input id="appKey" type="text" value="" /> </td>
        </tr>
        <tr>
            <th>secret</th><td> <input id="secret" type="text" value="" /> </td>
        </tr> 
        <tr>
            <th>access_token</th><td> <input id="access_token" type="text" value="" /> </td>
        </tr>              
    </table>
	<div id="content"></div>
</div>

<!-- js -->
<script src="jquery-1.10.2.min.js"></script>
<script src="sdk.js"></script>
<script src="format.js"></script>
<script type="text/javascript">
var params = {};
var aPairs, aTmp;  
var queryString = window.location.search.toString();
queryString = queryString.substr(1, queryString.length); //remove   "?"     
aPairs = queryString.split("&");  
for (var i = 0; i < aPairs.length; i++) {  
    aTmp = aPairs[i].split("=");  
    params[aTmp[0]] = aTmp[1];  
}

$(function(){
	var id = params.id;
	if(id) {
		var win = window.opener;
		var winDoc = win.document;
        var divDom = winDoc.getElementById(id);
        $('#content').html(divDom.innerHTML);
        $('#content').find('.new-win-btn').remove();
        
        document.title = $('#content').find('h2').eq(0).html();
        $('#url').val(winDoc.getElementById('url').value)
        $('#appKey').val(winDoc.getElementById('appKey').value)
        $('#secret').val(winDoc.getElementById('secret').value)
        $('#access_token').val(winDoc.getElementById('access_token').value)
        
        // 请求按钮
	    $('.api-block').find('.post-btn').click(function() {
	        var _parent = $(this).parents('.api-block');
	        var name = _parent.find('.api-name').val();
	        var version = _parent.find('.api-version').val();
	
	        var jsonData = {};
	        var formArray = _parent.find('form').serializeArray();
	
	        $.each(formArray,
	        function(i, field) {
	            jsonData[field.name] = field.value;
	        });
	
	        var _param = _parent.find('.api-data');
	        var _result = _parent.find('.api-result');
	        var _postResult = _parent.find('.post-result');
	
	        sdk.config({
	            url: $('#url').val(),
	            app_key: $('#appKey').val(),
	            secret: $('#secret').val(),
	        });
	
	        sdk.post({
	            name: name // 接口名
	            ,version:version
	            ,access_token:$('#access_token').val()
	            ,data: jsonData // 请求参数
	            ,callback: function(resp, postDataStr) { // 成功回调
	                _param.val(postDataStr);
	                _result.val(formatJson(JSON.stringify(resp)));
	                _postResult.show();
	            }
	        });
	        return false;
	    });
        
        $('#content').find('.post-btn').eq(0).click();
	}
});
</script>
</body>
</html>